var tgd = tgd || {};
tgd.Contests = tgd.Contests || {};
tgd.Contests.SameGame = tgd.Contests.SameGame || {};
tgd.Contests.SameGame.Solver = tgd.Contests.SameGame.Solver || {};
tgd.Contests.SameGame.View = tgd.Contests.SameGame.View || {};


tgd.Contests.SameGame.Solver.RandomSearcher = function (game, max, onmessage) {
	var _game = game;
	var _max = max;

	while (true) {
		if (_game.Field.HasAvailableGroup) {
			_game.Field.selectGroup(Math.floor(Math.random() * 100) % _game.Field.NumGroups);
		} else {
			if (_game.Score > _max) {
				_max = _game.Score;
				onmessage({ Max : _max, Game : _game.toString() });
			}
			_game.reset();
		}		
	}
}
